const ArticleDB = require('./../../utils/db');
class Article{
  static insertArticle({ title, summary, content, admin_tid }) {
    return new Promise((resolve, reject) => {
      ArticleDB.insertArticle( title, summary, content, admin_tid ).then(res => {
        resolve(res);
      }).catch(err => {
        reject(err);
      })
    })
  }
  static deleteArticle({ tid }) {
    return new Promise((resolve, reject) => {
      ArticleDB.deleteArticle(tid).then(res => {
        resolve(res);
      }).catch(err => {
        reject(err);
      })
    })
  }
  static updateArticle() {
    return new Promise((resolve, reject) => {
      ArticleDB.updateArticle(tid).then(res => {
        resolve(res);
      }).catch(err => {
        reject(err);
      })
    })
  }
  static getArticles() {
    return new Promise((resolve, reject) => {
      ArticleDB.getArticles().then(res => {
        resolve(res);
      }).catch(err => {
        reject(err);
      })
    })
  }
  static getArticle({ tid }) {
    return new Promise((resolve, reject) => {
      ArticleDB.getArticle(tid).then(res => {
        console.log(res, 'res')
        resolve(res);
      }).catch(err => {
        reject(err);
      })
    })
  }
  static getHotArticles() {
    return new Promise((resolve, reject) => {
      ArticleDB.getHotArticles().then(res => {
        resolve(res);
      }).catch(err => {
        reject(err);
      })
    })
  }
}

module.exports = Article;